package com.ccsu.joysport.controller;

//xyy
import com.ccsu.joysport.entity.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ccsu.joysport.service.ResultService;

import java.util.List;

@RestController
@RequestMapping("/results")
@CrossOrigin(origins = "http://localhost:63342")
public class ResultController {
    @Autowired
    private ResultService ResultService;
//
//    @GetMapping("/results")
//    public ResponseEntity<List<Result>> getResults() {
//    List<Result> results = ResultService.getAllResults();
//    return ResponseEntity.ok(results);
//}

    @GetMapping
    public List<Results> getAllResults() {
        return ResultService.getAllResults();
    }

    @GetMapping("/{id}")
    public Results getResultById(@PathVariable int id) {
        return ResultService.getResultById(String.valueOf(id));
    }

    @PostMapping
    public Results createResult(@RequestBody Results result) {
        return ResultService.saveResult(result);
    }

    @PutMapping("/{id}")
    public Results updateResult(@PathVariable String id, @RequestBody Results result) {
        result.setResultsID(Integer.parseInt(id));
        return ResultService.saveResult(result);
    }

    @DeleteMapping("/{id}")
    public void deleteResult(@PathVariable String id) {
        ResultService.deleteResult(id);
    }
}
